package com.example.demo01.Controller.mobileController;

import com.alibaba.fastjson.JSON;
import com.example.demo01.Entity.mobileEntity.ServiceOrder;
import com.example.demo01.Entity.mobileEntity.ServiceOrderSolved;
import com.example.demo01.Service.mobileService.ServiceOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ServiceOrderController {
    @Autowired
    private ServiceOrderService serviceOrderService;

    /**
     * 插入一条数据
     */
    @RequestMapping(value = "/serviceorder/INSERT/order")
    public int insert(
            @RequestParam(value = "username") String username,
            @RequestParam(value = "servicecontent") String servicecontent,
            @RequestParam(value = "serviceaddress") String serviceaddress,
            @RequestParam(value = "lon") String lon,
            @RequestParam(value = "lat") String lat
            )
    {
        return serviceOrderService.insert(new ServiceOrder(username,servicecontent,serviceaddress,Float.parseFloat(lon),Float.parseFloat(lat)));
    }


    /**
     * 获取所有服务订单数据
     * @return
     */
    @RequestMapping(value = "/serviceorder/GET/order")
    public String selectAll(
            @RequestParam(value = "username") String username) {
        String serviceOrderList = JSON.toJSONString(serviceOrderService.selectAll(username));
        System.out.println(serviceOrderList);
        return (serviceOrderList); }


    /**
     * 获取所有详细订单数据
     * */
    @RequestMapping(value = "/serviceorder/GET/allorder")
    public String selectAllDetailByPageSize(
           @RequestParam(value = "beginindex") Integer beginIndex,
           @RequestParam(value = "offset") Integer offSize)
    {
        return JSON.toJSONString(serviceOrderService.selectAllDetailByPageSize(beginIndex, offSize));
    }


    /**
     * 获取详细订单数据——带id值的未处理订单
     * */
    @RequestMapping(value = "/serviceorder/GET/allorder/withoutdeal")
    public String selectAllWidthoutDeal(
            @RequestParam(value = "beginindex") Integer beginIndex,
            @RequestParam(value = "offset") Integer offSize) {
        return JSON.toJSONString(serviceOrderService.selectAllWidthoutDeal(beginIndex, offSize)); }

    /**
     * 获取分页的总页数
     * @return
     */
    @RequestMapping(value = "/serviceorder/GET/totalsize")
    public int getTotalSize(
            @RequestParam(value = "pagesize") Integer pageSize) { return serviceOrderService.getTotalSize(pageSize); }

    /**
     * 获取未处理的消息的总页数
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/serviceorder/GET/unsolvedtotalsize")
    public int getTotalSizeOfUnSolved(
            @RequestParam(value = "pagesize") Integer pageSize) { return serviceOrderService.getTotalSizeOfUnSolved(pageSize); }

    /**
     * 更新服务消息记录
     */
    @RequestMapping(value = "/serviceorder/UPDATE/status")
    public int updateServiceRecord(
           @RequestParam(value = "username") String clientusername,
           @RequestParam(value = "lon") String lon,
           @RequestParam(value = "lat") String lat,
           @RequestParam(value = "ordertime") String ordertime,
           @RequestParam(value = "admin") String admin,
           @RequestParam(value = "status") String status) { return serviceOrderService.updateServiceRecord(clientusername, lon, lat, ordertime,admin,status); }
}
